package com.longyou.gateway;

import com.alibaba.druid.pool.DruidDataSource;
import com.unknow.first.api.common.config.ExceptionHandlerConfig;
import com.unknow.first.api.encrypt.config.ApiEncryptConfig;
import com.unkow.first.telegram.config.TelegramBotConfig;
import javax.sql.DataSource;
import lombok.extern.slf4j.Slf4j;
import org.cloud.dimension.config.SecurityFilterConfig;
import org.cloud.utils.SpringContextUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.session.data.redis.config.annotation.web.server.EnableRedisWebSession;

@SpringBootApplication(exclude = {RabbitAutoConfiguration.class, ExceptionHandlerConfig.class, SecurityFilterConfig.class,
    TelegramBotConfig.class, ApiEncryptConfig.class})
@EnableDiscoveryClient
@EnableRedisWebSession(maxInactiveIntervalInSeconds = 7200, redisNamespace = "system:spring:session")
@EnableFeignClients(basePackages = {"com.longyou.gateway.service.feign"})
@ComponentScan({"org.cloud.scheduler", "com.longyou.gateway"})
@Slf4j
public class GatewayApplication {

   public static void main(String[] args) {
      try {
         SpringApplication.run(GatewayApplication.class, args);
      } catch (Exception e) {
         log.error(e.getMessage(), e);
      }
   }

   @Bean
   public SpringContextUtil springContextUtil() {
      return new SpringContextUtil();
   }

   @Primary
   @Bean
   @ConfigurationProperties(prefix = "spring.datasource")
   public DataSource druidDataSource() {
      return new DruidDataSource();
   }

}
